/*
 * Copyright 2021 Muii
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitee.muii.echarts.utils;

import java.util.List;

public final class PropertyUtils {

    private PropertyUtils() {
        throw new AssertionError("无法获得" + this.getClass().getName() + "实例.");
    }

    /**
     * 若设置的propety包含在设定中的默认的properties中,则返回该值,否则返回空字符串
     *
     * @param properties 默认的properties
     * @param property   设置的property
     * @return property或空字符串
     */
    public static String propertyOrDefault(List<String> properties, String property) {
        return propertyOrDefault(properties, property, "");
    }

    /**
     * 若设置的propety包含在设定中的默认的properties中,则返回该值,否则返回默认property
     *
     * @param properties      默认的properties
     * @param property        设置的property
     * @param defaultProperty 默认property
     * @return property或默认property
     */
    public static String propertyOrDefault(List<String> properties, String property, String defaultProperty) {
        if (properties.contains(property)) {
            return property;
        }
        if (defaultProperty == null) {
            defaultProperty = "";
        }
        return defaultProperty;
    }

    /**
     * 若设置的propety包含在设定中的默认的properties中,则返回该值,否则返回空字符串
     *
     * @param properties 默认的properties
     * @param property   设置的property
     * @return property或空字符串
     */
    public static Double propertyOrDefault(List<Double> properties, Double property) {
        return propertyOrDefault(properties, property, null);
    }

    /**
     * 若设置的propety包含在设定中的默认的properties中,则返回该值,否则返回默认property
     *
     * @param properties      默认的properties
     * @param property        设置的property
     * @param defaultProperty 默认property
     * @return property或默认property
     */
    public static Double propertyOrDefault(List<Double> properties, Double property, Double defaultProperty) {
        if (properties.contains(property)) {
            return property;
        }
        return defaultProperty;
    }

}
